import { http } from '@/utils/http'
import type { cartInfoType } from '@/types/cart'

enum API {
  ADDCARTAPI = '/member/cart',
  GETCARTLISTAPI = '/member/cart',
  PUTCARTGOODAPI = '/member/cart/',
  PUTCARTGOODALLSELECTEDAPI = '/member/cart/selected',
  DELETECARTGOODSAPI = '/member/cart',
}
// 添加购物车商品参数的ts类型
interface addCartParamsType {
  skuId: string
  count: number
}
// 添加购物车的接口
export const postAddCartAPI = (data: addCartParamsType) => {
  return http<cartInfoType>({
    method: 'POST',
    url: API.ADDCARTAPI,
    data,
  })
}

// 获取购物车列表接口
export const getCartListAPI = () => {
  return http<cartInfoType[]>({
    method: 'GET',
    url: API.GETCARTLISTAPI,
  })
}
type putCartGoodParams = {
  selected?: boolean
  count?: number
}
// 修改购物车单品的接口
export const putCartGoodAPI = (skuId: string, data: putCartGoodParams) => {
  return http<cartInfoType>({
    method: 'PUT',
    url: API.PUTCARTGOODAPI + skuId,
    data,
  })
}

// 购物车全选/取消全选的接口
export const putCartGoodsAllSelectedAPI = (selected: boolean) => {
  return http({
    method: 'PUT',
    url: API.PUTCARTGOODALLSELECTEDAPI,
    data: {
      selected,
    },
  })
}

// 删除购物车商品的接口
export const deleteCartGoodsAPI = (ids: string[]) => {
  return http({
    method: 'DELETE',
    url: API.DELETECARTGOODSAPI,
    data: {
      ids
    } 
  })
}
